/*
 *  GWBitReduxEffect.cpp
 *  GWGlitch
 *
 *  Created by Michael Forrest on 01/03/2008.
 *  Copyright 2008 Grimaceworks. All rights reserved.
 *
 */

#include "GWBitReduxEffect.h"

void GWBitReduxEffect::Process(const Float32		*inSourceP,
								Float32		*inDestP,  
								UInt32 		inFramesToProcess,  
								UInt32		inNumChannels,  
								bool		&ioSilence){

	UInt32 nSampleFrames = inFramesToProcess;
	const Float32 *sourceP = inSourceP;
	Float32 *destP = inDestP;

	int bitParameter = kernel->GetParameter(kParam_BitReduxBits);
	
	float bit_depth = (float)bitParameter;
	float inv_bit_depth = 1.f / bit_depth;

	while (nSampleFrames-- > 0) {
		Float32 inputSample = *sourceP;
		*destP = (Float32) ((int)(inputSample*bit_depth)) * inv_bit_depth;
		
		sourceP += inNumChannels;
		destP += inNumChannels;
	}
}
